package com.wellsoft.mobileoa.utils;

import android.view.View;

import com.wellsoft.mobileoa.utils.widget.CheckboxWidget;
import com.wellsoft.mobileoa.utils.widget.ComboboxWidget;
import com.wellsoft.mobileoa.utils.widget.DatetimeWidget;
import com.wellsoft.mobileoa.utils.widget.FileWidget;
import com.wellsoft.mobileoa.utils.widget.HiddenWidget;
import com.wellsoft.mobileoa.utils.widget.InputWidget;
import com.wellsoft.mobileoa.utils.widget.LinkWidget;
import com.wellsoft.mobileoa.utils.widget.RadioWidget;
import com.wellsoft.mobileoa.utils.widget.TextWidget;
import com.wellsoft.mobileoa.utils.widget.TextareaWidget;

import com.wellsoft.mobileoa.wsmodel.WSOA_PageField;
import com.wellsoft.mobileoa.wsmodel.WSOA_PostField;
import com.wmobile.utils.ServiceResponse;

public abstract class BaseWidget {
	public WSOA_PageField field;
//	protected BaseActivity baseActivity;
	protected BaseView baseView;
	protected View view;
	protected boolean isVisible;
	public boolean hasEdited = false;
	public boolean hasValided = false;
	public boolean widgetEnable = true;

	public boolean getHasEdited() {
		return hasEdited;
	}

	public void setHasEdited(boolean hasEdited) {
		this.hasEdited = hasEdited;
	}

	public boolean isHasValided() {
		return hasValided;
	}

	public void setHasValided(boolean hasValided) {
		this.hasValided = hasValided;
	}

	public boolean isWidgetEnable() {
		return widgetEnable;
	}

	public void setWidgetEnable(boolean widgetEnable) {
		this.widgetEnable = widgetEnable;
	}

	public abstract View getView();

	public WSOA_PageField getField() {
		return field;
	}

	public void setField(WSOA_PageField field) {
		this.field = field;
	}

	public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}

	public WSOA_PostField getValue(){
		return null;
	}

	public String getRawValue(){
		return null;
	}

	public void setValue(Object widgetValue){
		
	}

	public void resetWidget(){
		
	}

	public ServiceResponse checkValid(){
		if(hasValided){
			return new ServiceResponse(true);
		}
		hasValided = true;
		return new ServiceResponse(true);
	}

	public static BaseWidget createWidgetFactory(WSOA_PageField field, BaseView baseView) {
		if (field.getFieldType().equals("checkbox")) {
			return new CheckboxWidget(field, baseView);
		} else if (field.getFieldType().equals("combobox")) {
			return new ComboboxWidget(field, baseView);
		} else if (field.getFieldType().equals("datetime")) {
			return new DatetimeWidget(field, baseView);
		} else if (field.getFieldType().equals("date")) {
			return new DatetimeWidget(field, baseView);
		} else if (field.getFieldType().equals("time")) {
			return new DatetimeWidget(field, baseView);
		} else if (field.getFieldType().equals("file")) {
			return new FileWidget(field, baseView);
		} else if (field.getFieldType().equals("hidden")) {
			return new HiddenWidget(field, baseView);
		} else if (field.getFieldType().equals("input")) {
			return new InputWidget(field, baseView);
		} else if (field.getFieldType().equals("link")) {
			return new LinkWidget(field, baseView);
		} else if (field.getFieldType().equals("radio")) {
			return new RadioWidget(field, baseView);
		} else if (field.getFieldType().equals("textarea")) {
			return new TextareaWidget(field, baseView);
		} else if (field.getFieldType().equals("text")) {
			return new TextWidget(field, baseView);
		}

		return null;
	}
}
